package lock;

import java.util.concurrent.TimeUnit;

/**
 * @program: javase
 * @description: 模拟死锁
 * @author: luolidong
 * @create: 2021-06-24 20:55
 * @version: 1.0
 */
public class DeadLock3 {
    private static Object object1 = new Object();
    private static Object object2 = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (object1) {
                //如果程序中出现异常，会释放锁
                try {
                    int a=9/0;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(() -> {
            synchronized (object1) {
                System.out.println("C");
                synchronized (object2) {
                    System.out.println("D");
                }
            }
        }).start();
    }
}
